using BLL.Interface;
using DotNetCoreApi.Filter;
using Microsoft.AspNetCore.Mvc;
using Model;
using Model.DTO;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace DotNetCoreApi.Controllers
{
    /// <summary>
    /// Account
    /// </summary>
    [Route("api/Account/[action]")]
    [ApiController]
    public class AccountController : BaseController
    {
        /// <summary>
        /// 注入bll
        /// </summary>
        public IAccountBLL bll { get; set; }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="entity">Account实体</param>
        /// <returns></returns>
        [HttpPost]
        [ResponseType(typeof(ReturnJson))]
        public async Task<bool> Add(Account entity)
        {
            return await bll.Add(entity);
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        [HttpDelete]
        [ResponseType(typeof(ReturnJson))]
        public async Task<bool> Delete(int id)
        {
            return await bll.Delete(id);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="entity">Account实体</param>
        /// <returns></returns>
        [HttpPut]
        [ResponseType(typeof(ReturnJson))]
        public async Task<bool> Update(Account entity)
        {
            return await bll.Update(entity);
        }
        /// <summary>
        /// 查询一个，通过id
        /// </summary>
        /// <param name="id">主键</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(ReturnJson<Account>))]
        public async Task<Account> Find(int id)
        {
            return await bll.Find(id);
        }
        /// <summary>
        /// 查询固定条数数据
        /// </summary>
        /// <param name="Limit">查询条数</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(ReturnJson<List<Account>>))]
        public async Task<List<Account>> List(int Limit = 5)
        {
            return await bll.List(Limit);
        }
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="limit">分页条件</param>
        /// <returns></returns>
        [HttpGet]
        [ResponseType(typeof(ReturnJson<DataList<Account>>))]
        public async Task<DataList<Account>> Pagination([FromQuery]Limit limit)
        {
            return await bll.Pagination(limit);
        }
    }
}
